import apis from '@/apis'
import axios from '@/apis/request'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useSettingStore = defineStore('setting', () => {
	const setting = ref({
		botId: '',
		kfMobile: '', // 客服电话
		agentName: ''
	})

	const errorNum = ref(5)

	function loadSetting() {
		return axios
			.get(apis.common.getBotId)
			.then(res => {
				setting.value = res
			})
			.catch(() => {
				if (errorNum.value !== 0) {
					errorNum.value--
					setTimeout(loadSetting, 1500)
				}
			})
	}

	return {
		setting,
		loadSetting
	}
})
